package com.segersten.othello.model;

import java.io.Serializable;

public class RoundAction implements Serializable {
	
	private Color color;
	private Point point;
	
	private RoundAction() {
	}
	
	private RoundAction(Point point,Color color) {
		this.color = color;
		this.point = point;
	}
	
	public static RoundAction createMove(Point point,Color color) {
	    assertNotNull(point, "point");
        assertNotNull(color, "color");
        return new RoundAction(point,color);
	}
	
	public static RoundAction createPass(Color color) {
        assertNotNull(color, "color");
        return new RoundAction(null,color);
    }

	public Color getColor() {
		return color;
	}

	public Point getPoint() {
		return point;
	}
	
	public boolean isPass() {
	    return point==null;
	}

	@Override
	public String toString() {
		return "Brick [color=" + color + ", point=" + point + "]";
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((point == null) ? 0 : point.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		RoundAction other = (RoundAction) obj;
		if (point == null) {
			if (other.point != null)
				return false;
		} else if (!point.equals(other.point))
			return false;
		return true;
	}

	public String toShortString() {
		return this.color.name()+":"+(this.point==null?"pass":this.point.getX()+":"+this.point.getY());
	}
	
	static private void assertNotNull(Object obj, String string)
    {
        if (obj == null)
        {
            throw new NullPointerException("Cannot be null " + string);
        }
    }
	
}
